home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
OpenProlog1d
/
Open Prolog Info
< prev
next >
Wrap
Text File
|
1991-02-01
|
20KB
|
476 lines
◊ Hi. Welcome to 'Open Prolog'.
This information refers to version 1.0d17.
Please read it carefully, especially the section on workarounds at the end.
This is a development version of the software, so it has bugs!
Save your work often.
Changes from previous versions are listed at the end of the file.
◊ Introduction
Open Prolog is an implementation of Edinburgh Prolog.
For information on Prolog itself, refer to one of the standard textbooks,
for instance 'Programming in Prolog' by Clocksin & Mellish,
'Introduction to Logic Programming' by Christopher Hogger, or the
excellent 'Artificial Intelligence through Prolog' by Neil C. Rowe.
(Titles are approximate.)
Open Prolog supports most of the features of DEC Prolog or C-Prolog,
including Definite Clause Grammars. Real-number arithmetic isn't supported.
The 'logical' assert and retract semantics of Lindholm & O'Keefe are
implemented.
Last Call Optimisation (often called Tail Recursion Optimisation) is done,
and indexing on the first argument of clause heads is performed,
mainly to detect determinacy so as to improve memory utilisation.
Open Prolog is called 'Open' because 'external' predicates can be dropped into
it via a Hypercard-like External Predicate Interface.
Open Prolog is not copy protected.
◊ System & Memory Requirements
Open Prolog runs in machines having System 6 (or later) system software.
If you try to run using an older system, it will complain.
This means that it won't run in anything 'less' than a Mac Plus.
Open Prolog seems to run in System 7 Beta Software (at this time).
Open Prolog will run under Multifinder in a memory allocation of
512K bytes or a bit less. 1024K bytes is recommended.
For most programs, more than 1024K won't improve performance much.
Open Prolog will run very comfortably on a 1MB machine with
Multifinder off.
Memory allocation and garbage collection are automatic.
However, space is not currently recovered when clauses are retracted, nor
when atoms or functors are no longer used.
For your information, the development environment is a Mac II with 5MB Ram.
Testing is also done on a Mac Plus with 4MB Ram. Systems are 6.0.3.
◊ Speed
Open Prolog runs the naive reverse benchmark at about 1900 Lips
on a Macintosh Plus. That means that it's about as fast - maybe even
a little faster - on a Mac Plus than C-Prolog on a Vax 11/780.
◊ About Open Prolog…
The 'About Open Prolog…' box contains a stacks indicator which
shows memory space broken into
Name (atom & functor), Index, Code, Global, Local & Trail spaces.
It's possible to watch the stacks grow and contract as the program runs,
but keeping the stacks indicator up-to-date slows execution quite a bit!
To avoid the speed penalty, it's possible to open and close the box while
the interpreter is running.
Alternatively, hiding the stacks indicator fully is just as effective.
◊ Using Open Prolog
Open Prolog is a text-oriented Prolog. If you're looking for
pretty pictures, try MacPaint, or write yourself a set of
external predicates. Seriously, if you have used DEC Prolog or C-Prolog,
then the style of use of Open Prolog is quite similar.
The Worksheet is the rough equivalent of their log file.
It's better because you can re-use chunks of it.
Standard input and output use the Worksheet by default.
◊ Startup
You can start Open Prolog either by opening some of its documents
or by opening the application itself.
◊ Home Folder
The folder that the Worksheet is in is called the Home Folder.
The Home Folder is chosen automatically as follows:
If you start Open Prolog by opening some of its documents from the
desktop, then the folder the documents are in becomes the
Home Folder.
If you start Open Prolog by opening it directly, then the folder it's in
becomes the Home Folder.
You can make any folder the Home Folder by saving the Worksheet
into it. See the section on file naming for the significance of the
Home Folder.
◊ Startup Actions
Before opening any files that you may have selected on the desktop,
Open Prolog will open a Worksheet in the home folder, always called
'Open Prolog Worksheet'.
Open Prolog does a few other things at startup:
It looks in the folder containing Open Prolog itself for a file called
'Open Prolog Options' and if it exists, it is consulted.
It looks in the home folder for a file called 'Open Prolog Startup' and if
it exists, it is consulted.
These files can be used to do routine things at startup, if desired.
Open Prolog Options should contain generally useful stuff, whereas
Open Prolog Startup, being specific to a folder, can contain more specialised
startup stuff.
For example, in the distribution of Open Prolog, a clause in
the Open Prolog Startup file checks for the existence of this file -
Open Prolog Info - and displays a message in a box.
There is a useful predicate defined in Open Prolog Options called
'Syntax Error'. When an error occurs reading from a file,
an error message is generated. The part that begins:
:- 'Syntax Error'(…
can be used to call the 'Syntax Error' predicate defined
in Open Prolog Options, which will try to open the file and show where
the error was. Try it by first consulting the file 'buggy syntax' below:
['buggy syntax'].
yes
Once the startup phase is finished, you are free to edit these files in the
normal way - there's nothing special about them.
◊ Usage
It helps to visualise the system as having two distinct parts -
the text editor and the Prolog interpreter.
◊ Text Editor
Your interaction with Open Prolog is via the text editor. With it, you can do
text-editing things on the Worksheet, and on up to seven other files.
Facilities offered are standard. Worth mentioning is 'Auto-indent'
which, if enabled, works by copying all the spaces & tabs from the start
of the previous line down to the start of this line. Also worth mentioning is
the 'Search All Windows' in the Find and Replace menus. All windows will
be searched, in front-to-back order until a match is found. The window in
which the match is found becomes the front window.
An open diamond - ◊ - appears opposite the name of the current front window
in the Window menu. Underlining indicates that the window needs to be
saved (either it's been changed, or it was never saved before).
The 'Display Selection' menu will scroll the caret or the selected text into
view.
◊ Window Characteristics
When windows are opened, they are opened in the same location (assuming
it's still visible), and with the same size as when they were
last closed.
Likewise, font, font size and the position of the flashing caret or selection
point are reset to they were when the window was last closed.
A window's maximum size if fixed according to the size of the
printable page in the currently selected printer.
◊ Locked Files
If a file is locked, or its volume is locked, then a small padlock icon
appears in the bottom left of its window. You can use the window
as normal, but you won't be allowed to save changes to that file.
◊ Worksheet
Most of the transactions that occur between you and Open Prolog will be
through a window. Generally, you issue commands by typing them into a
window and then notifying the interpreter about them, and Open Prolog sends
replies into the same window.
You can use any window for this, but the Worksheet will be chosen by default
or if any errors occur in using another window.
The Worksheet can't be closed.
◊ The 'Enter' Key
To communicate with the Prolog interpreter, you need to notify it in some
way that what you're doing is not just text editing. This is the function of
the 'Enter' key: all input from the text editor to the interpreter
is denoted by selecting the text and typing the <ENTER> key.
(This is similar to the arrangement in Apple's excellent MPW).
For example, below is the text of a command to consult the file 'benchmarks'.
To input it to the interpreter, select it (include the full stop) and
type <ENTER>:
[benchmarks].
Actually, you don't always have to select the whole thing; if the text
occupies only one line, position the cursor anywhere along it and type <ENTER>.
The whole line will then be taken as the text. This is called
'single line selection'.
Remember also that you use the <ENTER> key to denote any input to the
interpreter, not just command input.
Try evaluating the following query by single-line-selecting it.
You'll need to provide a further input in response; again, you
can use single line selection. Also, remember the full stop after
the term:
write('Please enter a Prolog term: '),read(Term),write('It''s: '),write(Term).
As is normal on DEC Prolog, where variable bindings are given as part
of the result of a query, the system waits for confirmation - type the
<ENTER> key - or a request for a retry - type a semicolon and the <ENTER> key.
◊ Prompts
The ?- prompt, familiar to many Prolog users, is no longer necessary, and
its inclusion would cause many implementation headaches.
In fact, all prompts, being inherently line-oriented, are gone from the
screen. Instead, we hope to put a 'status bar' in the bottom of the Worksheet
window in the future.
If you wish, you can enter a query preceded by a ?- - it won't make any
difference. If you precede your query by a :- then it will be performed without returning the variable bindings.
Examples:
?- write(H).
:- write(H),nl.
◊ Comment on <ENTER> & Prompts
Using the <ENTER> key to denote input to the interpreter has many advantages,
although it's probably a bit annoying to get used to. Likewise, the lack of
a prompt may be a bit disorienting.
The principal advantage of these changes is that you can do standard
text-editing freely and you can use any part of the Worksheet as
a source of input. In other words, you can re-use text on the Worksheet
over and over.
◊ During Evaluation
When Open Prolog is doing a long evaluation, it's still possible to use the
text editor in windows other than the Worksheet. The system will share
the processor between the interpreter and the text editor.
Generally, you won't notice the sharing being done.
Occasionally, however, depending on the evaluation being done,
the interpreter will keep the processor for a few
seconds to do garbage collection, or I/O. During that time the text editor
will 'freeze' and won't respond to the keyboard or other user input. This
is normal and is no cause for concern.
Please be careful to save your work frequently in this mode,
because if the evaluation causes Open Prolog to crash,
your work may be lost.
◊ Stopping an Evaluation
The standard 'Command-.' will halt a Prolog evaluation (eventually!).
◊ Background Operation
Open Prolog is Multifinder 'friendly' and will run in the Multifinder
background. This may be useful for long evaluations. Running under System 7,
it can be hidden and still be running.
◊ Built-In Predicates
To get a list of all predicates - normal, built-in and external,
there follows a sequence of commands to perform.
Select them all and hit the <ENTER> key:
'system$predicate'(X,Y,Z),functor(Y,X,A),
writeq(X),write('/'),write(A),write(.),write(' % '),write(Z),nl,fail.
Note: with a few exceptions, you should stay away from
anything with a $ in it, or anything with the word 'system' in it - you
may end up crashing the program.
The file 'Open Prolog Extras' has more information about
the non-standard predicates.
◊ Redefining Built-In Predicates
Open Prolog misbehaves if you try to redefine any built-ins or externals.
◊ Arithmetic
Arithmetic is standard 32-bit integer arithmetic. The following
predefined functions are provided:
unary minus: -
subtraction: -
addition: +
multiplication: *
integer division: /
mod (remainder): mod
bitwise and: /\
bitwise or: \/
bitwise not: ~
bitwise leftshift: <<
bitwise rightshift: >>
maximum integer: maxint
minimum integer: minint
time: cputime
The function 'cputime' gives the time in milliseconds since system startup
with a short-term granularity of approximately 16 mS (one system 'tick').
Use the built-in procedure 'system$seconds'(Seconds) for more
accurate timing of long intervals.
◊ Operators
The standard DEC Prolog operator definitions are made at startup.
You can get a list of operator definitions by evaluating the following query.
current_op(X,Y,Z),write(op(X,Y,Z)),write('.'),nl,fail.
◊ Extended Character Set
The full laser-printer character set (e.g. Times), which has more
characters than the original standard character sets like Chicago,
is assumed here.
Accented characters are treated as alphabetic, so atoms containing
accented characters don't need to be put in quotes.
Thus the following is legal:
Xävier = nóirín+jürgen+École+grève+daõ+çedilla+forêt.
◊ Sorting
Sorting is performed by the Mac's International Utilities, which
should handle accented characters correctly.
Note that case is ignored when sorting functor or atom names.
◊ Files
The file-handling arrangements are essentially unchanged from DEC Prolog,
except where obviously necessary. Some built-in predicates have been
omitted, notably 'close/1' and 'fileErrors' & 'nofileerrors'.
◊ File Naming
File naming follows standard Mac practice. To specify a file in the
home folder, just give its name (as 'benchmarks' above).
If it's in another folder, you can give its full pathname. For example, to
consult a file called 'Utilities' on a disk or volume called 'Open Prolog Disk'
in a folder called 'Samples' you could use:
['Open Prolog Disk:Samples:Utilities'].
Alternatively, you can specify a file by its partial pathname (i.e. the extra information needed to 'get from' the Home Folder to there).
For instance, on this release disk you can use the following to consult
the file 'Tak' in the folder 'Samples' which is in the Home Folder:
[':Samples:Tak'].
◊ End of File & End of Line
- End of line & end of file treatment is the same as in DEC Prolog.
- When reading from a file, the last term is always 'end_of_file'.
- When get-ing or get0-ing from a file, the last character is code 26.
. Carriage Returns (ASCII code 13), generally signifying end-of-line in a file,
are filtered out of the get or get0 stream and replaced by code 31.
Input from a window never results in an end of file condition.
◊ nl
- nl outputs a Carriage Return (ASCII code 13).
◊ get & get0
- get & get0 always return the next character, irrespective of whether it is
'printable' or not.
◊ Debugging
The main Program Debugging facility is the trace/1 predicate.
You can trace the execution of a predicate by calling it via trace:
%assuming you've already consulted 'tak' above…
trace(tak(12,8,4,N)).
The commands available are:
<ENTER> - trace
s<ENTER> - step over
a<ENTER> - abort
f<ENTER> - fail
@<ENTER> - break for one command
It's not possible to spy.
The unknown/2 predicate specifies what happens when a call is made
to an unknown predicate. (Allowable values are fail or trace.)
E.g., select:
unknown(X,trace).
This will set Open Prolog to abort when an unknown call is made.
Try it now by selecting:
huh(What).
A snazzy source-level debugger, a là SADE, is under development.
◊ System Error Messages:
There are three kinds of error messages:
A. A simple information box with 'OK' as the only option.
B. A 'Diagnostic' or 'Breakpointer' information box.
This is intended for giving debugging
information, and if it turns up in normal operation it means that a special
condition has occured.
C. Whenever Open Prolog detects a system error, it will warn you about it.
You are generally given some information about the source and kind of the
error. Naturally, it isn't always possible to predict what will happen
if you continue operating the system.
Summarising: When you get an error message,
if you are given a choice, it's best (initially) to exit.
You normally get to save your files and windows, although sometimes
the nature of the error causes more errors to be made as the files &
windows are being saved. It that happens, you lose your fi…
Experience will tell what's best to do in a situation.
(I sure hope you don't get a lot of that experience…)
I'd appreciate you mailing me with the circumstances and nature of
B & C type messages, and of undesirable effects of A type messages.
◊ Problems with Open Prolog
Here are the known significant difficulties with Open Prolog at the moment.
There are simple workarounds for them all.
1. The absolute maximum size of any file that can be seen in an Open Prolog
window is limited to 32767 characters.
Actually the realistic maximum is about 16000.
This limit only applies to files that you want to open as windows.
Open Prolog neither truncates window files nor warns you about impending
problems.
So, for example, if your program produces large output files, that's OK as
long as you don't want to open them as windows from Open Prolog.
Workarounds:
Break your files into smaller files.
Trim the Worksheet periodically so that is doesn't get too big.
To view and process larger text files, you'll need to use a text processor
(MPW highly recommended) or word processor in text mode (MS Word or
MacWrite II).
2. Currently, the window system and the file system are not integrated.
So, changes you make to a file in a window are not automatically
reflected in the file when it is being consulted.
Workaround - after making changes to a file in a window,
save it before consulting or reconsulting it.
(Actually, it's a good idea to save your work each time anyway…)
Likewise, a window must be closed before your program
starts to output to it.
Another difficulty is if you try to open a window & file from a predicate
and the file is already open into a window of a different name; then the
system will not recognise the already open window as the one it wants,
and will refuse to open another.
3. Tab characters are not properly represented or printed - instead a tab
always occupies exactly one space. If you intend using your files with
another text/word processor, then you should put them in…
4. The implementation of cuts in a disjunctive call (i.e. ;/2) is not
according to the standard.
According to the standard, cut in a disjunction should have the same effect
as a cut in the disjunction's parent. In Open Prolog, a cut in a disjunction has
only a local effect.
Secondly, disjunctive calls are compiled on the fly in Open Prolog, so they
much slower than normal code.
Both these points will be fixed on the next revision.
5. Similarly to above, a nested conjunctive call has the same problems -
cuts have only local effects, and the nested calls are compiled on the fly.
◊ External Predicates
If you really want to write some external predicates, mail me & I'll send you
the MPW Pascal files you need together with an example.
Be aware that it's likely that the interface will change in the future.
◊ Revision History
-1.0d17
1. Cosmetic improvements, particularly multi-screen handling.
2. New window-handling predicates.
3. External Predicate Interface Inprovement
- 1.0d16
1. A crash-without-warning bug has been cured.
2. A bug in call(X) which declated a call like call((read(X),X)) illegal because
the second call was uninstantiated has been cured.
3. The DCG compiler has been changed a little.
4. Various cosmetic improvements.
5. A number of extra predicates to handle window I/O have been added.
- 1.0d15
1. A restriction which required all <ENTER>ed text (including commands)
to be on the Worksheet has been removed.
2. Sometimes the way in which part of a line was picked for selection
was a little unpredictable. This has been cured.
3. A -192 warning caused by a harmless fault in the System
when DA Menuz and Suitcase were present has been removed.
- 1.0d14
Initial Release